/***************************************************************
*  Copyright (c) 2007 by GroupMe! Team (www.groupme.net)
*  All rights reserved.
*
*  This file is part of the GroupMe! Project. Source code of 
*  this project is closed and redistribution of this code is
*  prohibited. 
*  
*  Contact: http://www.groupme.net
*
*  This copyright notice MUST APPEAR in all copies of the file!
***************************************************************/
package net.groupme.search.strategy.model;

import net.groupme.model.Identifiable;
import net.groupme.model.Resource;

/**
 * created on Jul 4, 2007
 * 
 * This class defines a simple structure for assigning weights to resources.
 * 
 * @author Fabian Abel, <a href="mailto:abel@l3s.de">abel@l3s.de</a>
 * @author last edited by: $Author: fabian $
 * 
 * @version $Revision: 1.4 $ $Date: 2008-05-28 16:13:38 $
 */
public class WeightedResource extends AbstractWeightedIdentifiable{
	
	/** the resource that is assigned with a weight */
	public Resource resource;
	
	/** the weight that is associated to the resource */
	public double weight;
	
	/**
	 * Creates a new WeightedResource instance.
	 * @param resource resource that is assigned with a weight 
	 * @param weight weight that is associated to the resource
	 */
	public WeightedResource(Resource resource, double weight){
		this.resource = resource;
		this.weight = weight;
	}

	/* (non-Javadoc)
	 * @see net.groupme.search.strategy.model.AbstractWeightedIdentifiable#getIdentifiable()
	 */
	@Override
	public Identifiable getIdentifiable() {
		return resource;
	}
	/* (non-Javadoc)
	 * @see net.groupme.search.strategy.model.AbstractWeightedIdentifiable#getWeight()
	 */
	@Override
	public double getWeight() {
		return weight;
	}

	/* (non-Javadoc)
	 * @see net.groupme.search.strategy.model.AbstractWeightedIdentifiable#setWeight(double)
	 */
	@Override
	public void setWeight(double weight) {
		super.setWeight(weight);
		this.weight = weight;
	}

	/* (non-Javadoc)
	 * @see net.groupme.search.strategy.model.AbstractWeightedIdentifiable#clone()
	 */
	@Override
	public AbstractWeightedIdentifiable clone() {
		return new WeightedResource(this.resource, this.weight);
	}
	
	/**
	 * This equals-method just compares the URIs of the two identifiables.
	 * @param other the other {@link AbstractWeightedIdentifiable} to compare with
	 * @return returns <code>true</code> if the URIs of the identifiables (of this and the given
	 * {@link AbstractWeightedIdentifiable} instances) are equal.
	 */
	@Override
	public boolean equals(Object other) {
		if(other instanceof AbstractWeightedIdentifiable){
			return this.getIdentifiable().getId().equals(((AbstractWeightedIdentifiable)other).getIdentifiable().getId());
		}else{
			return false;
		}
	}

}
